package Blog0;

import java.util.Scanner;

class Animal {
    protected String name;

    public Animal(String name) {
        this.name = name;
    }
    public void trait() {

    }
}

class Tiger extends Animal {
    public Tiger(String name) {
        super(name); // 调用父类的构造方法，放在第一行
    }

    @Override // 重写，注解: 错误提醒，人和编译器都可以读懂的注释
    public void trait() {
        System.out.println(super.name+" 跑得飞快");
    }
}

class Whale extends Animal {
    public Whale(String name) {
        super(name);
    }

    @Override
    public void trait() {
        System.out.println(super.name+" 游得飞快");
    }

}


class Eagle extends Animal {
    public Eagle(String name) {
        super(name);
    }

    @Override
    public void trait() {
        System.out.println(super.name+" 飞得飞快");
    }

    public void fly() {
        System.out.println("Whale :: fly");
    }

}



class Shape {
    public void draw() {
        // 啥也不干
    }
}

class Cycle extends Shape {
    @Override // 重写；注解：错误提醒，任何编译器都可以读懂的注释
    public void draw() {
        System.out.println("画一个 🔴");
    }
}

class React extends Shape {
    @Override // 重写
    public void draw() {
        System.out.println("画一个 🔺");
    }
}

public class Blog05 {
    public static void main(String[] args) {
        Shape[] shapes = new Shape[]{new Cycle(),new React()};

        for (Shape s: shapes) {
            s.draw();
        }
    }


    public static void func(Shape shape) {
        shape.draw();
    }
    public static void main8(String[] args) {
        Shape shape = new Cycle();
        Shape shape1 = new React(); // 向上转型
        func(shape);
        func(shape1);
    }




    public static void main7(String[] args) {
        Animal animal = new Eagle("神雕");
        if(animal instanceof Eagle) {
            Eagle eagle = (Eagle)animal;
            eagle.trait();
            eagle.fly();
        } else {
            System.out.println("NO");
        }

        if(animal instanceof Whale) {
            Whale whale = (Whale)animal;
            whale.trait();
        } else {
            System.out.println("NO NO");
        }
    }


    public static void main6(String[] args) {
        Animal animal = new Eagle("年轻的鹰");
        Animal animal2 = new Whale("年轻的鲸鱼");

        animal.trait();
        animal2.trait();
    }

    public static void main5(String[] args) {
        Animal animal = new Eagle("年轻的鹰");
        animal.trait();
        System.out.println("**********************");
        Eagle eagle = new Eagle("年轻的鹰");
        eagle.trait();
    }

    public static Animal func() {   // 方法的返回值
        Animal animal = new Tiger("年轻的老虎");
        return animal;

    }
    public static void main4(String args[]) {
        func().trait();
    }

    public static void func1(Animal animal) {
        animal.trait();
    }


    public static void main3(String[] args) {
        Animal animal = new Tiger("老虎");
        Animal animal1 = new Whale("鲸鱼");
        Animal animal2 = new Eagle("鹰");

        animal.trait();
        animal1.trait();
        animal2.trait();
    }

    public static void main2(String[] args) {
        Animal animal = new Tiger("老虎");
        Animal animal1 = new Whale("鲸鱼");
        Animal animal2 = new Eagle("鹰");
        func1(animal);
        func1(animal1);
        func1(animal2);
    }
}
